home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / dirutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-27  |  16.2 KB  |  788 lines

  1. /* dirutil.c - MS-DOS directory reading routines
  2.  *
  3.  * Bdale Garbee, N3EUA, Dave Trulli, NN2Z, and Phil Karn, KA9Q
  4.  * Directory sorting by Mike Chepponis, K3MC
  5.  * New version using regs.h by Russell Nelson.
  6.  * Rewritten for Turbo-C 2.0 routines by Phil Karn, KA9Q 25 March 89
  7.  *
  8.  * Added path filter functions and applied to dodir
  9.  * also used by ftpcli.c, added current directory  
  10.  * storage capability (11/92 WA3DSP)
  11.  * Bugfixes in the above by WG7J
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <dir.h>
  16. #include <dos.h>
  17. #include <stdlib.h>
  18. #include <time.h>
  19. #include "global.h"
  20. #include "config.h"
  21. #include "proc.h"
  22. #include "session.h"
  23. #include "dirutil.h"
  24. #include "commands.h"
  25. #include "smtp.h"
  26.  
  27. #ifdef CALLSERVER
  28. #include <string.h>
  29. #include <alloc.h>
  30. extern char *CDROM; /* buckbook.c: defines CDROM drive letter e.g. "s:"  */
  31. #endif
  32.  
  33. struct dirsort {
  34.     struct dirsort *next;
  35.     struct ffblk de;
  36. };
  37. #define    NULLSORT (struct dirsort *)0
  38.  
  39. static void commas __ARGS((char *dest));
  40. static int fncmp __ARGS((char *a, char *b));
  41. static void format_fname_full __ARGS((FILE *file,struct ffblk *sbuf,int full,
  42.     int n));
  43. static void free_clist __ARGS((struct dirsort *this));
  44.  
  45. #ifdef    notdef
  46. static int getdir_nosort __ARGS((char *path,int full,FILE *file));
  47. #endif
  48. static int nextname __ARGS((int command, char *name, struct ffblk *sbuf));
  49. static void print_free_space __ARGS((char *path,FILE *file,int n));
  50. void undosify __ARGS((char *s));
  51. extern void crunch __ARGS((char *buf,char *path));
  52. static char *wildcardize __ARGS((char *path));
  53.  
  54. #ifdef TNOS_68K
  55. #define REGFILE    (FA_DIREC)
  56. #define ALLFILES "*"
  57. #include <modes.h>
  58. #else
  59. #define REGFILE    (FA_HIDDEN|FA_SYSTEM|FA_DIREC)
  60. #define ALLFILES "*.*"
  61. #endif
  62.  
  63. #define    insert_ptr(list,new)    (new->next = list,list = new)
  64.  
  65.  
  66. /* Create a directory listing in a temp file and return the resulting file
  67.  * descriptor. If full == 1, give a full listing; else return just a list
  68.  * of names.
  69.  */
  70. FILE *
  71. dir(path,full)
  72. char *path;
  73. int full;
  74. {
  75. FILE *fp;
  76. char *path2;
  77.  
  78.     if((fp = tmpfile()) != NULLFILE){
  79.         if (!path)
  80.             path = Command->curdirs->dir;
  81.         if (full)
  82.             fprintf(fp, "Directory of %s at %s\n\n", path, Hostname);
  83.         path2 = strdup(make_dir_path(2,path,Command->curdirs->dir));
  84.         getdir(path2,full,fp);
  85.         free (path2);
  86.         rewind(fp);
  87.     }
  88.     return fp;
  89. }
  90.  
  91. /* find the first or next file and lowercase it. */
  92. static int
  93. nextname(command, name, sbuf)
  94. int command;
  95. char *name;
  96. struct ffblk *sbuf;
  97. {
  98.     int found;
  99.  
  100.     switch(command){
  101.     case 0:
  102.         found = findfirst(name,sbuf,REGFILE);
  103.         break;
  104.     default:
  105.         found = findnext(sbuf);
  106.     }
  107.     found = (found == 0);
  108.     if(found)
  109.         strlwr(sbuf->ff_name);
  110.  
  111.     return found;
  112. }
  113.  
  114.  
  115. /* wildcard filename lookup */
  116. int
  117. filedir(name,times,ret_str)
  118. char *name;
  119. int times;
  120. char *ret_str;
  121. {
  122. static struct ffblk sbuf;
  123. int rval;
  124.  
  125.     switch(times){
  126.         case 0:        rval = findfirst(name,&sbuf,REGFILE);
  127.                 break;
  128.         default:    rval = findnext(&sbuf);
  129.                 break;
  130.     }
  131.     if(rval == -1)
  132.         ret_str[0] = '\0';
  133.     else     /* Copy result to output */
  134.         strcpy(ret_str, sbuf.ff_name);
  135.     return rval;
  136. }
  137.  
  138.  
  139. /* do a directory list to the stream 
  140.  * full = 0 -> short form, 1 is long
  141. */
  142. int
  143. getdir(path,full,file)
  144. char *path;
  145. int full;
  146. FILE *file;
  147. {
  148.     struct ffblk sbuf;
  149.     int command = 0;
  150.     int n = 0;
  151.     struct dirsort *head, *here, *new;
  152.  
  153.     path = wildcardize(path);
  154.  
  155.     head = NULLSORT;    /* No head of chain yet... */
  156.     for(;;){
  157.         pwait (NULL);
  158.         if (!nextname(command, path, &sbuf))
  159.             break;
  160.         command = 1;    /* Got first one already... */
  161.         if (sbuf.ff_name[0] == '.')    /* drop "." and ".." */
  162.             continue;
  163.  
  164.         new = (struct dirsort *) mallocw(sizeof(struct dirsort));
  165.         new->de = sbuf;    /* Copy contents of directory entry struct */
  166.  
  167.         /* insert it into the list */
  168.         if (!head || fncmp(new->de.ff_name, head->de.ff_name) < 0) {
  169.             insert_ptr(head, new);
  170.         } else {
  171.             register struct dirsort *this;
  172.             for (this = head;
  173.                 this->next != NULLSORT;
  174.                 this = this->next)
  175.                 if (fncmp(new->de.ff_name, this->next->de.ff_name) < 0)
  176.                     break;
  177.             insert_ptr(this->next, new);
  178.         }
  179.     } /* infinite FOR loop */
  180.  
  181.     for (here = head; here; here = here->next)
  182.         format_fname_full(file,&here->de,full,++n);
  183.  
  184.     /* Give back all the memory we temporarily needed... */
  185.     free_clist(head);
  186.  
  187.     if(full)
  188.         print_free_space(path, file, n);
  189.  
  190.     return 0;
  191. }
  192.  
  193. static int
  194. fncmp(a,b)
  195. register char *a, *b;
  196. {
  197.         int i;
  198.  
  199.     for(;;){
  200. #ifndef TNOS_68K
  201.         if (*a == '.')
  202.             return -1;
  203.         if (*b == '.')
  204.             return 1;
  205. #endif
  206.         if ((i = *a - *b++) != 0)
  207.             return i;
  208.         if (!*a++)
  209.             return -1;
  210.     }
  211. }
  212.  
  213. #ifdef ALLCMD
  214. /* Change working directory */
  215. int
  216. docd(argc,argv,p)
  217. int argc;
  218. char *argv[];
  219. void *p;
  220. {
  221.     if(argc > 1){
  222.         if (!dir_ok(argv[1],Command->curdirs)) {
  223.             tprintf("Invalid Drive/Directory - %s\n",argv[1]);
  224.             return 1;
  225.         }
  226.     }
  227.     tprintf("Local Directory - %s\n", Command->curdirs->dir);
  228.     return 0;
  229. }
  230.  
  231.  
  232. #ifdef MSDOS
  233. /* Change working drive */
  234. int
  235. dodrive(argc,argv,p)
  236. int argc;
  237. char *argv[];
  238. void *p;
  239. {
  240. char **margv;
  241.  
  242.     margv = (char **)callocw(2,sizeof(char *));
  243.     margv[1] = strdup(argv[0]);
  244.     docd(2,margv,p);
  245.     free(margv[1]);
  246.     free(margv);
  247.     return 0;
  248. }
  249. #endif
  250.  
  251.  
  252. char *
  253. defpath (curdirs,path)
  254. struct cur_dirs *curdirs;
  255. char *path;
  256. {
  257. #ifndef TNOS_68K
  258. int drive;
  259.  
  260.     drive = tolower(path[0]) - '`';
  261.     if (strlen (path) == 2 && path[1] == ':' && curdirs->curdir[drive] != NULLCHAR)
  262.         return curdirs->curdir[drive];
  263.     else
  264. #endif
  265.         return path;
  266. }
  267.  
  268.  
  269. #if (defined(ALLCMD) || defined(ALLSESSIONS))
  270. extern int morecmd();
  271. /* List directory to console */
  272. int
  273. dircmd(argc,argv,p)
  274. int argc;
  275. char *argv[];
  276. void *p;
  277. {
  278.     char *path, *file;
  279.     FILE *fp;
  280.     char tmpname[80];
  281.     char curdir[128];
  282.     char **margv;
  283.  
  284.     if (argc > 1)        {
  285.         file = strdup (make_fname (Command->curdirs->dir, defpath (Command->curdirs, argv[1])));
  286.         path=strdup(make_dir_path(argc,file,Command->curdirs->dir));
  287.         free (file);
  288.     } else
  289.         path = strdup (Command->curdirs->dir);
  290.     margv = (char **)callocw(2,sizeof(char *));
  291.     tmpnam(tmpname);
  292.     fp = fopen(tmpname,WRITE_TEXT);
  293.     getdir(path,1,fp);
  294.     free(path);
  295.     fclose(fp);
  296.     margv[1] = strdup(tmpname);
  297.     morecmd(2,margv,p);
  298.     free(margv[1]);
  299.     free(margv);
  300.     unlink(tmpname);
  301.     return 0;
  302. }
  303.  
  304. int
  305. dodir(argc,argv,p)
  306. int argc;
  307. char *argv[];
  308. void *p;
  309. {
  310.     char **pargv;
  311.     int i;
  312.  
  313.     if(Curproc->input == Command->input) {
  314.         /* Make private copy of argv and args,
  315.          * spawn off subprocess and return.
  316.          */
  317.         pargv = (char **)callocw(argc + 1,sizeof(char *));
  318.         for(i=0;i<argc;i++)
  319.             pargv[i] = strdup(argv[i]);
  320.         pargv[i] = NULL;
  321.         newproc("dir",512,(void (*)())dircmd,argc,(void *)pargv,p,1);
  322.     } else
  323.         dircmd(argc,argv,p);
  324.     return 0;
  325. }
  326.  
  327. #endif
  328.  
  329.  
  330. /* Create directory */
  331. int
  332. domkd(argc,argv,p)
  333. int argc;
  334. char *argv[];
  335. void *p;
  336. {
  337. char path[128];
  338.     
  339.     strcpy(path,make_fname(Command->curdirs->dir,argv[1]));
  340.     
  341.     if(mkdir(path) == -1)
  342.         tprintf("Can't make %s: %s\n",path,sys_errlist[errno]);
  343.     return 0;
  344. }
  345. /* Remove directory */
  346. int
  347. dormd(argc,argv,p)
  348. int argc;
  349. char *argv[];
  350. void *p;
  351. {
  352. char path[128];
  353.     
  354.     strcpy(path,make_fname(Command->curdirs->dir,argv[1]));
  355.     if(rmdir(path) == -1)
  356.         tprintf("Can't remove %s: %s\n",path,sys_errlist[errno]);
  357.     return 0;
  358. }
  359. #endif /*ALLCMD*/
  360.  
  361. /*
  362.  * Return a string with commas every 3 positions.
  363.  * the original string is replace with the string with commas.
  364.  *
  365.  * The caller must be sure that there is enough room for the resultant
  366.  * string.
  367.  *
  368.  *
  369.  * k3mc 4 Dec 87
  370.  */
  371. static void
  372. commas(dest)
  373. char *dest;
  374. {
  375.     char *src, *core;    /* Place holder for malloc */
  376.     unsigned cc;        /* The comma counter */
  377.     unsigned len;
  378.  
  379.     len = strlen(dest);
  380.     /* Make a copy, so we can muck around */
  381.     core = src = strdup(dest);
  382.  
  383.     cc = (len-1)%3 + 1;    /* Tells us when to insert a comma */
  384.  
  385.     while(*src != '\0'){
  386.         *dest++ = *src++;
  387.         if( ((--cc) == 0) && *src ){
  388.             *dest++ = ','; cc = 3;
  389.         }
  390.     }
  391.     free(core);
  392.     *dest = '\0';
  393. }
  394. /* fix up the filename so that it contains the proper wildcard set */
  395. static char *
  396. wildcardize(path)
  397. char *path;
  398. {
  399. #ifndef TNOS_68K
  400. #define THISSIZE 64
  401. #else
  402. #define THISSIZE 128
  403. #endif
  404. struct ffblk sbuf;
  405. static char ourpath[THISSIZE];
  406.  
  407.     /* Root directory is a special case */
  408.     if(path == NULLCHAR ||
  409.        *path == '\0'
  410. #ifndef TNOS_68K
  411.        || strcmp(path,"\\") == 0 ||
  412.        strcmp(path,"/") == 0)    {
  413.         path = "\\*.*";
  414. #else
  415.         )    {
  416.         path = "*";
  417. #endif
  418.         return path;
  419.         }
  420. #ifdef CALLSERVER
  421.     if  (CDROM != NULLCHAR &&  strcmp(path, CDROM) == 0)  {
  422.       path = (char *) mallocw(7); /* THIS causes a memory leak ! - WG7J */
  423.       sprintf(path, "%s/*.*", CDROM);
  424.     }
  425. #endif
  426.  
  427.     /* if they gave the name of a subdirectory, append \*.* to it */
  428.     if (
  429. #ifdef TNOS_68K
  430.         (*path == '/' && !(strchr(path+1, '/'))) ||
  431. #endif
  432.         (nextname(0, path, &sbuf) &&
  433.         (sbuf.ff_attrib & FA_DIREC) &&
  434.         !nextname(1, path, &sbuf))) {
  435.  
  436.         /* if there isn't enough room, give up -- it's invalid anyway */
  437.         if (strlen(path) + 4 > (THISSIZE - 1)) return path;
  438.         strcpy(ourpath, path);
  439. #ifndef TNOS_68K
  440.         strcat(ourpath, "\\*.*");
  441. #else
  442.         strcat(ourpath, "/*");
  443. #endif
  444.         return ourpath;
  445.     }
  446.     return path;
  447. }
  448.  
  449. static void
  450. format_fname_full(file, sbuf, full, n)
  451. FILE *file;
  452. struct ffblk *sbuf;
  453. int full, n;
  454. {
  455. char line_buf[50];        /* for long dirlist */
  456. char cbuf[20];            /* for making line_buf */
  457. int k, l;
  458.  
  459.     strcpy(cbuf,sbuf->ff_name);
  460.     if(sbuf->ff_attrib & FA_DIREC) strcat(cbuf, "/");
  461.     if (full) {
  462.         /* Long form, give other info too */
  463. #ifndef TNOS_68K
  464.         sprintf(line_buf,"%-13s",cbuf);
  465. #else
  466.         sprintf(line_buf,"%-14s",cbuf);
  467.         if (strlen (cbuf) > 14)
  468.             strcpy (&line_buf[12], "..");
  469. #endif
  470.         if(sbuf->ff_attrib & FA_DIREC)    {
  471. #ifndef TNOS_68K
  472.             strcat(line_buf,"           ");/* 11 spaces */
  473. #else
  474.             strcat(line_buf,"          ");/* 10 spaces */
  475. #endif
  476.         } else {
  477.             sprintf(cbuf,"%ld",sbuf->ff_fsize);
  478.             commas(cbuf);
  479. #ifndef TNOS_68K
  480.             sprintf(line_buf+strlen(line_buf),"%10s ",cbuf);
  481. #else
  482.             sprintf(line_buf+strlen(line_buf),"%9s ",cbuf);
  483. #endif
  484.         }
  485.         sprintf(line_buf+strlen(line_buf),"%2d:%02d %2d/%02d/%02d%s",
  486.           (sbuf->ff_ftime >> 11) & 0x1f,    /* hour */
  487.           (sbuf->ff_ftime >> 5) & 0x3f,    /* minute */
  488.           (sbuf->ff_fdate >> 5) & 0xf,    /* month */
  489.           (sbuf->ff_fdate ) & 0x1f,        /* day */
  490.           (sbuf->ff_fdate >> 9) + 80,    /* year */
  491.           (full == 2) ? " | \n" : (n & 1) ? "   " : "\n");
  492.         fputs(line_buf,file);
  493.     } else {
  494.         fputs(cbuf,file);
  495.         fputs("\n",file);
  496.     }
  497. }
  498. /* Provide additional information only on DIR */
  499. static void
  500. print_free_space(path, file, n)
  501. char *path;
  502. FILE *file;
  503. int n;
  504. {
  505.     unsigned long free_bytes, total_bytes;
  506.     char s_free[20], s_total[20];
  507.     char cbuf[20];
  508.     struct dfree dtable;
  509.     unsigned long bpcl;
  510. #ifndef TNOS_68K
  511.     char resolved[80];    /* may need as little as 67 */
  512.     union REGS regs;
  513.     struct SREGS sregs;
  514.     int drive;
  515.  
  516.     /* do an undocumented call to find wich drive this mane resolves to */
  517.     regs.x.si = FP_OFF(path);
  518.     sregs.ds = FP_SEG(path);
  519.     regs.x.di = FP_OFF(resolved);
  520.     sregs.es = FP_SEG(resolved);
  521.     regs.h.ah = 0x60;
  522.     intdosx(®s,®s,&sregs);
  523.     drive = resolved[0] - '@';
  524.  
  525. #endif
  526.     if(n & 1)
  527.         fputs("\n",file);
  528.  
  529.     /* Find disk free space */
  530. #ifndef TNOS_68K
  531.     getdfree(drive,&dtable);
  532. #else
  533.     getdfree(path,&dtable);
  534. #endif
  535.  
  536.     bpcl = dtable.df_bsec * dtable.df_sclus;
  537.     free_bytes  = dtable.df_avail * bpcl;
  538.     total_bytes = dtable.df_total * bpcl;
  539.  
  540.     sprintf(s_free,"%ld",free_bytes);
  541.     commas(s_free);
  542.     sprintf(s_total,"%ld",total_bytes);
  543.     commas(s_total);
  544.  
  545.     if(n)
  546.         sprintf(cbuf,"%d",n);
  547.     else
  548.         strcpy(cbuf,"No");
  549.  
  550.     fprintf(file,"%s file%s. %s bytes free. Disk size %s bytes.\n",
  551.         cbuf,(n==1? "":"s"),s_free,s_total);
  552. }
  553. static void
  554. free_clist(this)
  555. struct dirsort *this;
  556. {
  557.     struct dirsort *next;
  558.  
  559.     while (this != NULLSORT) {
  560.         next = this->next;
  561.         free(this);
  562.         this = next;
  563.     }
  564. }
  565. #ifdef    notdef
  566. static int
  567. getdir_nosort(path,full,file)
  568. char *path;
  569. int full;
  570. FILE *file;
  571. {
  572.     struct ffblk sbuf;
  573.     int command;
  574.     int n = 0;    /* Number of directory entries */
  575.  
  576. /*    path = wildcardize(path); */
  577.     command = 0;
  578.     while(nextname(command, path, &sbuf)){
  579.         command = 1;    /* Got first one already... */
  580.         if (sbuf.ff_name[0] == '.')    /* drop "." and ".." */
  581.             continue;
  582.         format_fname_full(file, &sbuf, full, ++n);
  583.     }
  584.     if(full)
  585.         print_free_space(path, file, n);
  586.     return 0;
  587. }
  588. #endif
  589.  
  590. /* Translate those %$#@!! backslashes to proper form */
  591. void
  592. undosify(s)
  593. char *s;
  594. {
  595.     if (s)        {
  596.         while(*s != '\0')    {
  597.             if(*s == '\\')
  598.                 *s = '/';
  599.             s++;
  600.         }
  601.     }
  602. }
  603.  
  604.  
  605. char *
  606. make_dir_path (count,arg,curdir)
  607. int count;
  608. char *arg, *curdir;
  609. {
  610.     char path[128], *q;
  611.  
  612.     undosify(arg);
  613.     undosify(curdir);
  614.     if (count>=2) {
  615.        q=arg;
  616.        q+=strlen(arg)-1;
  617. #ifndef TNOS_68K
  618.        if (*q=='/' || *q==':') {
  619. #else
  620.        if (*q=='/') {
  621. #endif
  622.           strcpy(path,arg);
  623.           strcat(path,ALLFILES);
  624.        } else
  625.           strcpy(path,arg);
  626.     } else {
  627.        strcpy(path,ALLFILES);
  628.     }
  629.     return (make_fname(curdir,path));
  630. }        
  631.  
  632. char*
  633. make_fname(curdir,fname)
  634. char *curdir, *fname;
  635. {
  636. char *p;
  637. static char new_name[128];
  638.  
  639.     strcpy(new_name,curdir);
  640.     undosify(fname);
  641.     if (fname && *fname)    {
  642. #ifndef TNOS_68K
  643.         if (fname[0]=='/' || (strchr(fname,':') != NULLCHAR) )
  644. #else
  645.         if (fname[0]=='/')
  646. #endif
  647.             return fname;
  648.         else    {
  649.             p=new_name;
  650.             p+=strlen(p)-1;
  651.             if (*p=='/')
  652.                 *p='\0';
  653.             crunch(new_name,fname);
  654. #ifndef TNOS_68K
  655.             if (new_name[strlen(new_name)-1] == ':')
  656.                 strcat (new_name, "/");
  657. #endif
  658.         }
  659.     }
  660.     return new_name;
  661. }
  662.  
  663. /* Check Drive/Directory for validity - 1=OK, 0=NOGOOD */
  664.  
  665. int
  666. dir_ok(newpath,dirs)
  667. char *newpath;
  668. struct cur_dirs *dirs;
  669. {
  670. #ifndef TNOS_68K
  671.     char *a, curpath[128];
  672.     char buf[128],fullpath[128];
  673.     int result,drive;
  674.  
  675.     drive=dirs->drv;
  676.     undosify(newpath);
  677.     strlwr(newpath);
  678.     a=newpath;
  679.     if ((*(a+1)==':') && (isalpha(*a))){
  680.         drive=tolower(*a)-'`';
  681.         strcpy(buf,a+2);
  682.         if (dirs->curdir[drive]==NULLCHAR) {
  683.             if(!getcurdir(drive,curpath)) {
  684.                 undosify(curpath);
  685.                 sprintf(fullpath,"%c:/%s",drive+'`',curpath);
  686.                 dirs->curdir[drive]=strdup(fullpath);
  687.                 dirs->drv=drive;
  688.                 dirs->dir=dirs->curdir[drive];
  689.             }
  690.         }
  691.     } else {
  692.         strcpy(buf,newpath);
  693.     }
  694.  
  695.     if((a=dirs->curdir[drive])!=NULLCHAR) {
  696.         if ((*(a+1)==':') && (isalpha(*a))){
  697.             if (*(a+2)=='/')
  698.                strcpy(curpath,a+3);
  699.             else
  700.                strcpy(curpath,a+2);
  701.         } else {
  702.             strcpy(curpath,a);
  703.         }
  704.     } else {
  705.       strcpy(curpath,"");
  706.     }
  707.  
  708.     if (*buf!='/') {
  709.       crunch(curpath,buf);
  710.     } else {
  711.       strcpy(curpath,buf+1);
  712.     }
  713.     a=curpath;
  714.     sprintf(fullpath,"%c:%s%s",drive+'`',(*a!='/' ? "/" : ""),curpath);
  715.  
  716.     if((result=access(fullpath,0)+1)==1) {
  717.         if(dirs->curdir[drive])
  718.             free(dirs->curdir[drive]);
  719.         dirs->curdir[drive]=strdup(fullpath);
  720.         dirs->drv=drive;
  721.         dirs->dir=dirs->curdir[drive];
  722.     }
  723.     return result;
  724. #else
  725. int result, new = 0;
  726. char fullpath[1024];
  727.  
  728.     undosify(newpath);
  729.     strlwr(newpath);
  730.     result = ((access (newpath, S_IFDIR) == -1) ? 0 : 1);
  731.     if (result)    {
  732. /*        chdir (newpath);    */
  733.         new = (*newpath == '/');
  734.         sprintf(fullpath,"%s%s%s",!new ? dirs->dir : "",!new ? "/" : "",newpath);
  735.         free (dirs->dir);
  736.         dirs->dir = strdup (fullpath);
  737.     }
  738.     return (result);
  739. #endif
  740. }
  741.  
  742. char *
  743. init_dirs(dirs)
  744. struct cur_dirs *dirs;
  745. {
  746. #ifndef TNOS_68K
  747.     char buf[128],fullpath[128];
  748.     int x,drive;
  749.  
  750.     for(x=0;x<=26;x++)
  751.        dirs->curdir[x]='\0';
  752.  
  753.     drive=getdisk()+1;
  754.     getcurdir(drive,buf);
  755.     undosify(buf);
  756.     strlwr(buf);
  757.     sprintf(fullpath,"%c:/%s",drive+'`',buf);
  758.     dirs->curdir[drive]=strdup(fullpath);
  759.     dirs->drv=drive;
  760.     dirs->dir=dirs->curdir[drive];
  761.     return dirs->curdir[drive];
  762. #else
  763. char fullpath[1024];
  764.  
  765.     dirs->dir = strdup (getcwd (fullpath, 1024));
  766.     return (dirs->dir);
  767. #endif
  768. }
  769.  
  770. void
  771. free_dirs(dirs)
  772. struct cur_dirs *dirs;
  773. {
  774. #ifndef TNOS_68K
  775.     int x;
  776.  
  777.     for(x=0;x<=26;x++) {
  778.         if (dirs->curdir[x])
  779.             free(dirs->curdir[x]);
  780.     }
  781. #else
  782.     free (dirs->dir);
  783. #endif
  784. }
  785.  
  786.  
  787.  
  788.